package com.combo.auth;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class ComboActiveReceiver extends BroadcastReceiver {


    public static final String ACTIVATE_COMPLETED = "com.aspire.jshdc.action.ACTIVATE_COMPLETED";
    public static final String ACTIVATE_FAILURE = "com.aspire.jshdc.action.ACTIVATE_FAILER";
    ComboCallback comboCallback;

    public void setComboCallback(ComboCallback comboCallback) {
        this.comboCallback = comboCallback;
    }

    public void registerReceiver(Context context) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ACTIVATE_COMPLETED);
        filter.addAction(ACTIVATE_FAILURE);
        context.registerReceiver(this, filter);
    }

    public void unregisterReceiver(Context context) {
        context.unregisterReceiver(this);
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (ACTIVATE_COMPLETED.equals(action)) {
            if (comboCallback != null) {
                comboCallback.onSuccess();
            }
        } else if (ACTIVATE_FAILURE.equals(action)) {
            if (comboCallback != null) {
                String code = intent.getStringExtra("code");
                String message = intent.getStringExtra("message");
                comboCallback.onFailure(code, message);
            }
        }
    }
}
